<link type="text/css" href="${request.contextPath}/static/oms/iframe/plugins/ueditor/themes/default/css/ueditor.css" rel="stylesheet" />
<link href="${request.contextPath}/static/oms/iframe/plugins/bootstrap-image-picker/css/image-picker.css"  rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${request.contextPath}/static/oms/iframe/plugins/fileupload/css/jquery.fileupload-ui.css">
<div class="row">
	<div class="col-md-12">
		<form id="siteAddForm" class="form-horizontal" action="${request.contextPath}/cms/site/add" method="post" onsubmit="return false">
			<div class="box-body" >
				<div class="form-group">
					<label id="siteNameLabel" for="siteName" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="name" id="siteName" placeholder="输入名称...">
					</div>
					<label id="shortTitleLabel" for="siteShortTitle" class="col-sm-2 control-label">短标题</label>
					<div class="col-sm-3">
						<input type="text" class="form-control" name="shortTitle" id="siteShortTitle" placeholder="输入短标题...">
					</div>
				</div>
				<div class="form-group">
					<label id="siteTitleLabel" for="siteTitle" class="col-sm-2 control-label">标题</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="title" id="siteTitle" placeholder="输入标题...">
					</div>
				</div>
				<div class="form-group">
					<label id="siteFaviconLabel" for="siteFavicon" class="col-sm-2 control-label">快截图标</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" name="favicon" id="siteFavicon"  readonly placeholder="输入快捷方式图标...">
					</div>
					<div class="col-sm-4 ad">
						<span class="btn btn-success fileinput-button">
							<i class="glyphicon glyphicon-plus"></i>
							<span>选择文件</span>
							<input id="siteFaviconFileupload"  class="fileinput-button"  type="file" name="file"  data-url="/system/config/file/add?type=1" multiple>
						 </span>
					</div>
				</div>
				<div class="form-group">
					<label id="siteLogoLabel" class="col-sm-2 control-label" >Logo</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" name="logo" id="siteLogo" readonly placeholder="输入Logo...">
					</div>
					<div class="col-sm-4">
						<span class="btn btn-success fileinput-button">
							<i class="glyphicon glyphicon-plus"></i>
							<span>选择文件</span>
							<input id="siteLogoFileupload"  class="fileinput-button"  type="file" name="file"  width="60" data-url="/system/config/file/add?type=1" multiple>
						 </span>
					</div>
				</div>
				<div class="form-group">
					<label id="siteKeywordsLabel" for="siteKeywords" class="col-sm-2 control-label">关键字</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="keywords" id="siteKeywords" placeholder="输入关键字...">
					</div>
				</div>
				<div class="form-group">
					<label id="siteProtocolLabel" for="siteProtocol" class="col-sm-2 control-label">协议</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" name="protocol" id="siteProtocol"  placeholder="输入协议...">
					</div>
					<label id="siteDomainLabel" for="siteDomain" class="col-sm-1 control-label">域名</label>
					<div class="col-sm-3">
						<input type="text" class="form-control" name="domain" id="siteDomain" placeholder="输入域名...">
					</div>
					<label id="sitePortLabel" for="sitePort" class="col-sm-1 control-label">端口</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" name="port" id="sitePort" placeholder="输入端口...">
					</div>
				</div>
				<div class="form-group">
					<label id="siteCopyrightLabel" class="col-sm-2 control-label" >版权信息</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="copyright" id="siteCopyright" placeholder="输入版权信息...">
					</div>
				</div>
				<div class="form-group">
					<label id="siteSeqLabel" for="siteSeq" class="col-sm-2  control-label">排序号</label>
					<div class="col-sm-4">
						<input  class="form-control" name="priority" id="siteSeq" type="number" placeholder="输入排序号...">
					</div>
					<label id="siteStatusLabel" for="siteStatus" class="col-sm-1  control-label">状态</label>
					<div class="col-sm-4">
						<select class="form-control" id="siteStatus"  name="validStatus" style="width: 100%;" placeholder="选择状态...">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="siteDescriptionLabel" class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="description" id="siteDescription" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="siteRemarkLabel" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" name="remark" id="siteRemark" placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" id="siteAddFormErrorMsgContainer">
					<span class="error-icon"></span>
					<span id="siteAddFormErrorMsg" class="error-msg" ></span>
				</div>
			</div>
			<div class="box-body">
				<div class="text-center">
					<button type="submit" class="btn btn-primary btn-sm" ><i class="fa fa-save"></i> 保存</button>
					<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 取消</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script src="${request.contextPath}/static/oms/iframe/plugins/fileupload/js/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="${request.contextPath}/static/oms/iframe/plugins/bootstrap-image-picker/js/imagePicker.js"></script>
<script src="${request.contextPath}/static/oms/iframe/plugins/fileupload/js/jquery.fileupload.js"></script>
<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
	
	if ($form.length === 1 && $form.validate()) {
		$.post(form.action, $form.serialize(),
			function(result) {
				if (result.success) {
					$("#lgModal").modal('hide');
		        	alertMsg(result.message,"success");
					dataGridReload();
				} else {
					$form.find(".error-msg").show();
					$form.find(".error-msg").html(result.message);
				}
			}, 'json');
	}
}

$(function() {
    $("#siteFavicon").imageDynamicPicker();
    $("#siteLogo").imageDynamicPicker();
    $("#siteFaviconFileupload").fileupload({
        url: "/system/config/file/add",
        autoUpload: true,
        dataType: 'json',
        acceptFileTypes: /\.(jpg|png|gif)$/i, //浏览器支持File API才有效
        maxFileSize: 2097152, //2M，浏览器支持File API才有效
        send: function(e, data){
            alertMsg('上传中...',"success");
        },
        done: function (e, data) {
            alertMsg("上传成功", "success");
            $("#siteFavicon").val(data._response.result.data.url);
        },
        fail: function(e, data) {
            alertMsg("上传失败", "success");
        }
    });
    $("#siteLogoFileupload").fileupload({
        url: "/system/config/file/add",
        autoUpload: true,
        dataType: 'json',
        acceptFileTypes: /\.(jpg|png|gif)$/i, //浏览器支持File API才有效
        maxFileSize: 2097152, //2M，浏览器支持File API才有效
        send: function(e, data){
            alertMsg('上传中...',"success");
        },
        done: function (e, data) {
            alertMsg("上传成功", "success");
            $("#siteLogo").val(data._response.result.data.url);
        },
        fail: function(e, data) {
            alertMsg("上传失败", "success");
        }
    });

    $("#siteStatus").select2({
        data: StatusStore,
        theme: "bootstrap"
    });
	$siteAddForm = $("#siteAddForm");
	$siteAddForm.validate({
		rules: {
			name: {
				required: true
			},
            title: {
				required: true
			},
            protocol: {
				required: true
			},
            domain: {
                required: true
            },
			copyright:{
			    required: true
            },
			description: {
				required: true
			},
            priority: {
				required: true
			}
		},
		messages: {
            name:{
				required:"名称不能为空！"
			},
            title:{
				required:"标题不能为空！"
			},
            protocol:{
				required:"协议不能为空！"
			},
            domain:{
                required:"域名不能为空！"
            },
            copyright:{
                required:"版权信息不能为空！"
            },
			description: {
				required: "描述不能为空！"
			},
            priority: {
				required: "排序号不能为空！"
			}
		},
		submitHandler:ajaxSubmit,
		errorLabelContainer:"#siteAddFormErrorMsgContainer",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$siteAddForm.find(".error-msg").html(errorList[0].message);
			}else{
				$siteAddForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>